package org.flynenu.ums.common.ticket;

import org.flynenu.core.cache.lru.LruCache;

/**
 * Ʊ�ֿ� ��ʹ�ø���֮ǰ��������������С�� ���򽫲���Ĭ�ϴ�СΪ1��
 * 
 * @author Lionel
 * 
 */
public class TicketsCacheImpl implements TicketCache {
	public final static int defaultCacheSize = 1000000;
	private LruCache<Integer, String> cache = new LruCache<Integer, String>();
	
	private static  TicketsCacheImpl instance = null;
	
	private TicketsCacheImpl(){
		
	}
	
	public static TicketCache  instance(){
		if(instance != null){
			return instance;
		}
		
		synchronized(TicketsCacheImpl.class){
			if(instance != null){
				return instance;
			}
			
			instance = new TicketsCacheImpl();
		}
		
		return instance;
	}
	
	public Ticket queryTicketNo(int uid) {
		String ticketNo = (String) cache.getObject(uid);
		Ticket ticket = new Ticket();
		ticket.setTicketNo(ticketNo);
		ticket.setId(uid);
		
		return ticket;
	}

	@Override
	public void saveTicketNo(Ticket ticket) {
		cache.putObject(ticket.getId(), ticket.getTicketNo());
	}

	public void setCache(LruCache<Integer, String> cache1) {
		if(cache == null){
			cache = cache1;
		}
	}
}
